<?php
namespace app\admin\model;
use think\Model;
use Db;
/**
* 文章分类
*/
class Arctype extends Base
{
	
	 protected $autoWriteTimestamp = true;
     protected $insert = ['status' => 1];

	//查询address表中所有数据  
    public static function type_all(){  
        $arr = self::select();  
        return self::list_level($arr,$pid=0,$level=0);  
    }  
    //递归遍历数据  


    public static function edit($id='0',$post)
    {
    	if($id != 0 && !empty($post)){
    		$data = self::get($id);
    		$data->title = $post['title'];
    		$data->pid = $post['pid'];
    		$data->keywords = $post['keywords'];
    		$data->description = $post['description'];
    		$data->type_img = $post['type_img'];
            $data->status = $post['status'];

    		if($data->save() > 0){
    			return true;
    		}else{
    			return false;
    		}


    	}
    }


    protected static function init()
    {
        /**
         * 删去前
         */
        self::beforeDelete(function ($user) {
            //有子栏目 栏目中有文章时，不能删 &&与运算时就是两边同时成立时为真，|| 或时两边一个成立就是真
            if(Db::name('arctype')->where('pid',$user->id)->count() > 0 || Db::name('article')->where('typeid',$user->id)->count() > 0){
                return false;
            }
        });
    } 









}